package com.chongaizhen.local.transactional.service;

import com.chongaizhen.local.transactional.mapper.StudentMapper;
import com.chongaizhen.local.transactional.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Transactional(rollbackFor = Exception.class)
    public void testTransactional() {

        Student student = studentMapper.selectByPrimaryKey(1);

        Student student1 = new Student();
        student1.setId(2);
        student1.setName("222");
        studentMapper.insertSelective(student1);

        int a = 10/0;

        Student student2 = new Student();
        student2.setId(2);
        student2.setName("333");
        studentMapper.insertSelective(student2);

    }

}
